package ch.usi.inf.pf2.editor;

import ch.usi.inf.pf2.Sheet;
import ch.usi.inf.pf2.cell.Cell;

/**
 * This class contains an action that defines the text delete
 * 
 * @author Lorenzo Baracchi
 *
 */
public class TextDelete extends TextManagement 
{

	/**
	 * Create an object able to delete some text in a cell.
	 * @param sheet The sheet where the cell is.
	 * @param rowIndex The numeric index of the cell.
	 * @param columnIndex The literal index of the cell.
	 */
	public TextDelete(Sheet sheet, int rowIndex, int columnIndex) 
	{
		super(sheet, rowIndex, columnIndex);
	}

	
	/**
	 * Store the current content of a cell into oldText
	 * and set newText to empty.
	 */
	@Override
	public void evaluate () 
	{
		Cell c = sheet.getCell(getColumnIndex(), getRowIndex());
		setOldText(c.getContent().toString());
		setNewText("");
		c.setContent(getNewText());
	}

	
	/**
	 * Undo the previous deleting of the text contained into a cell.
	 */
    @Override
    public void restore ()
    {
	   Cell c = sheet.getCell(getColumnIndex(), getRowIndex());
	   c.setContent(getOldText());	
    }

	
}
